package pers.cz.node;

import org.openqa.selenium.remote.RemoteWebDriver;
import pers.cz.mxgraph.MxCell;
import pers.cz.selenium.component.SwitchComponent;

/**
 * @program: PostGirl-panent
 * @description: 切换节点，包括切换页面，切换iframe等
 * @author: Cheng Zhi
 * @create: 2023-01-23 14:04
 **/
public class SwitchNode extends AbstractNode {

    public SwitchNode(MxCell mxCell) {
        super(mxCell);
    }

    @Override
    public void runNode(NodeCallBack callBack) throws Exception{
        RemoteWebDriver driver = getDriver();
        // 注意，切换页面并不需要获取fullPath,只需要使用驱动切换即可。
        SwitchComponent switchComponent = new SwitchComponent(driver);
        String operation = mxCell.getMxObjectData().get("operation");
        // 获取操做类型 1: 切换到最新页面， 2：切换到最新iframe
        if ("1".equals(operation)) {
            switchComponent.switchNewPage();
        } else if ("2".equals(operation)) {
            switchComponent.switchNewIframe();
        } else if ("3".equals(operation)){
            String ext = mxCell.getMxObjectData().get("ext");
            switchComponent.switchPage(Integer.valueOf(ext));
        }
    }

    @Override
    public void verify() {

    }

    @Override
    public String getName() {
        return mxCell.getName();
    }
}
